<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:param name="formPrefix" select="data/response/form/@prefix" />
	<xsl:param name="editorId" select="number(0)" /> 
	
	<!-- HEADER & LATIN & EMAIL -->
	<xsl:template match="form/field[@character='header' or @character='latin' or @character='email'  or @character='tags']">
		<div class="form_field">
			<div class="form_field_label">
				<label for="field_{@id}">
					<xsl:value-of select="title" />
					<xsl:text>:</xsl:text>
				</label>
			</div>
			<div class="form_field_input">
				<input id="field_{@id}" class="form_input_text" type="text" name="data[{$formPrefix}][{@name}]">
					<xsl:attribute name="value">
						<xsl:value-of select="value" />
					</xsl:attribute>
				</input>
				<xsl:if test="error != ''">
					<br /><span class="form_field_error"><xsl:value-of select="error" /></span>
				</xsl:if>
				<xsl:if test="help != ''">
					<br /><span class="form_field_help"><xsl:value-of select="help" /></span>
				</xsl:if>
			</div>
		</div>
	</xsl:template>
	
	<!-- GUIDE & MULTIGUIDE -->
	<xsl:template match="form/field[@character='guide' or @character='multiguide']">
		<div class="form_field">
			<div class="form_field_label">
				<label for="field_{@id}">
					<xsl:value-of select="title" />
					<xsl:text>:</xsl:text>
				</label>
			</div>
			<div class="form_field_input">
				<select id="field_{@id}" class="form_input_select" name="data[{$formPrefix}][{@name}][]">
					<xsl:if test="@character = 'multiguide'">
						<xsl:attribute name="size">5</xsl:attribute>
						<xsl:attribute name="multiple">multiple </xsl:attribute>
					</xsl:if>
					
					<option value="">-- выберите</option>
					
					<xsl:for-each select="value">
						<option>
							<xsl:attribute name="value">
								<xsl:value-of select="@id" />
							</xsl:attribute>
							<xsl:if test="@selected='selected'">
								<xsl:attribute name="selected">
									<xsl:text>selected</xsl:text>
								</xsl:attribute>
							</xsl:if>
							
							<xsl:value-of select="." />
						</option>
					</xsl:for-each>				
				</select>
				<xsl:if test="error != ''">
					<br /><span class="form_field_error"><xsl:value-of select="error" /></span>
				</xsl:if>
				<xsl:if test="help != ''">
					<br /><span class="form_field_help"><xsl:value-of select="help" /></span>
				</xsl:if>
			</div>
		</div>
	</xsl:template>
	
	<!-- INTEGER & FLOAT -->
	<xsl:template match="form/field[@character='integer']">
		<div class="form_field">
			<div class="form_field_label">
				<label for="field_{@id}">
					<xsl:value-of select="title" />
					<xsl:text>:</xsl:text>
				</label>
			</div>
			<div class="form_field_input">
				<input id="field_{@id}" class="form_input_integer" type="text" name="data[{$formPrefix}][{@name}]">
					<xsl:attribute name="value">
						<xsl:value-of select="value" />
					</xsl:attribute>
				</input>
				<xsl:if test="error != ''">
					<br /><span class="form_field_error"><xsl:value-of select="error" /></span>
				</xsl:if>
				<xsl:if test="help != ''">
					<br /><span class="form_field_help"><xsl:value-of select="help" /></span>
				</xsl:if>
			</div>
		</div>
	</xsl:template>
	
	<!-- BOOLEAN -->
	<xsl:template match="form/field[@character='boolean']">
		<div class="form_field">
			<div class="form_field_label">
				<label for="field_{@id}">
					<xsl:value-of select="title" />
					<xsl:text>: </xsl:text>
				</label>
				<input id="field_{@id}" type="checkbox" value="1" name="data[{$formPrefix}][{@name}]">
					<xsl:if test="value = '1'">
						<xsl:attribute name="checked">
							<xsl:text>checked</xsl:text>
						</xsl:attribute>
					</xsl:if>
				</input>
				<xsl:if test="error != ''">
					<br /><span class="form_field_error"><xsl:value-of select="error" /></span>
				</xsl:if>
				<xsl:if test="help != ''">
					<br /><span class="form_field_help"><xsl:value-of select="help" /></span>
				</xsl:if>
			</div>
		</div>
	</xsl:template>
	
	<!-- TEXT -->
	<xsl:template match="form/field[@character='text']">
		<xsl:param name="editorName" select="concat ('oEditor_', $editorId + 1)" />
				
		<div class="form_field">
			<div class="form_field_label">
				<label for="field_{@id}">
					<xsl:value-of select="title" />
					<xsl:text>:</xsl:text>
				</label>
			</div>
			<div class="form_field_input">
				<script type="text/javascript">
					var <xsl:value-of select="$editorName" /> = new SimpleEditor;
				</script>
				<div class="simple_editor">
					<a title="Выделить жирным" href="javascript:void(0);" onclick="{$editorName}.insertTag ('b',null); this.blur();"><img src="{$baseURI}/images/editor/b.png" alt="" /></a>
					<a title="Выделить курсивом" href="javascript:void(0);" onclick="{$editorName}.insertTag ('i',null); this.blur();"><img src="{$baseURI}/images/editor/i.png" alt="" /></a>
					<a title="Подчеркнуть" href="javascript:void(0);" onclick="{$editorName}.insertTag ('u',null); this.blur();"><img src="{$baseURI}/images/editor/u.png" alt="" /></a>
					<a title="Зачеркнуть" href="javascript:void(0);" onclick="{$editorName}.insertTag ('s',null); this.blur();"><img src="{$baseURI}/images/editor/s.png" alt="" /></a>
					<a title="Параграф" href="javascript:void(0);" onclick="{$editorName}.insertTag ('p',null); this.blur();"><img src="{$baseURI}/images/editor/p.png" alt="" /></a>
					<a title="Цитата" href="javascript:void(0);" onclick="{$editorName}.insertTag ('blockquote',null); this.blur();"><img src="{$baseURI}/images/editor/blockquote.png" alt="" /></a>
					<a title="Вставить ссылку" href="javascript:void(0);" onclick="{$editorName}.insertLink (); this.blur();"><img src="{$baseURI}/images/editor/link.png" alt="" /></a>
					<a title="Вставить изображение" href="javascript:void(0);" onclick="{$editorName}.insertImage (); this.blur();"><img src="{$baseURI}/images/editor/image.png" alt="" /></a>
					<!--a title="Вставить ссылку на пользователя" href="javascript:void(0);" onclick="{$editorName}.insertUserLink (); this.blur();"><img src="{$baseURI}/images/editor/user.png" alt="" /></a-->
					<a title="Вставить видео" href="javascript:void(0);" onclick="{$editorName}.insertVideo (); this.blur();"><img src="{$baseURI}/images/editor/video.png" alt="" /></a>
				</div>
				<textarea id="field_{@id}" class="form_textarea" name="data[{$formPrefix}][{@name}]">
					<xsl:value-of select="value" />
				</textarea>
				<script><xsl:value-of select="$editorName" />.init ('<xsl:value-of select="concat ('field_', @id)" />');</script>
				<xsl:if test="error != ''">
					<br /><span class="form_field_error"><xsl:value-of select="error" /></span>
				</xsl:if>
				<xsl:if test="help != ''">
					<br /><span class="form_field_help"><xsl:value-of select="help" /></span>
				</xsl:if>
			</div>
		</div>
	</xsl:template>
	
	<!-- DATE -->
	<xsl:template match="form/field[@character='date' or @character='birthdate']">
		<div class="form_field">
			<div class="form_field_label">
				<label for="field_{@id}">
					<xsl:value-of select="title" />
					<xsl:text>:</xsl:text>
				</label>
			</div>
			<div class="form_field_input">
				<input id="field_{@id}" class="form_input_date" type="text" name="data[{$formPrefix}][{@name}]">
					<xsl:attribute name="value">
						<xsl:value-of select="value" />
					</xsl:attribute>
				</input>
				<xsl:text> (дд.мм.гггг)</xsl:text>
				<xsl:if test="error != ''">
					<br /><span class="form_field_error"><xsl:value-of select="error" /></span>
				</xsl:if>
				<xsl:if test="help != ''">
					<br /><span class="form_field_help"><xsl:value-of select="help" /></span>
				</xsl:if>
			</div>
			
			<script type="text/javascript">
				$(function() {
					$("#<xsl:value-of select="concat('field_', @id)" />").datepicker({ dateFormat: 'dd.mm.yy' });
				});
			</script>					
		</div>		
	</xsl:template>
	
	<!-- IMAGE -->
	<xsl:template match="form/field[@character='image']">
		<div class="form_field">
			<div class="form_field_label">
				<label for="field_{@id}">
					<xsl:value-of select="title" />
					<xsl:text>:</xsl:text>
				</label>
				<xsl:if test="value != ''">
					<br />
					<img alt="">
						<xsl:attribute name="src">
							<xsl:value-of select="value" />
						</xsl:attribute>
					</img>
				</xsl:if>
			</div>
			<div class="form_field_input">
				<input id="field_{@id}" class="form_input_image" type="file" name="data[{$formPrefix}][{@name}]">
				</input>
				<xsl:if test="error != ''">
					<br /><span class="form_field_error"><xsl:value-of select="error" /></span>
				</xsl:if>
				<xsl:if test="help != ''">
					<br /><span class="form_field_help"><xsl:value-of select="help" /></span>
				</xsl:if>
			</div>
		</div>
	</xsl:template>

</xsl:stylesheet>